<?php
/**
 * Created by PhpStorm.
 * User: testypp
 * Date: 2018/1/2
 * Time: 下午3:21
 */


class Api_Comment extends PhalApi_Api {

    // 每个方法的参数设定
    public function getRules() {
        return array(
            'getCommentByTopicID' => array(
                'topicid' => array('name' => 'topicid', 'min' => 1, 'require' => true, 'desc' => 'topicID'),
            ),
            'addComment' => array(
                'userid' => array('name' => 'userid', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'username' => array('name' => 'username', 'min' => 1, 'require' => true, 'desc' => '用户昵称'),
                'commentstring' => array('name' => 'commentstring', 'min' => 1, 'require' => true, 'desc' => '评论详情'),
                'ishot' => array('name' => 'ishot', 'min' => 1, 'require' => true, 'desc' => '是否是热门'),
                'topicid'=> array('name' => 'topicid', 'min' => 1, 'require' => true, 'desc' => 'topicID')
            ),
        );
    }



    // 根据TopicID获取评论
    public function getCommentByTopicID() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $domain = new Domain_Comment();

        $info = $domain->getCommentByTopicID($this->topicid);

//        if (empty($info)) {
//            DI()->logger->debug('用户不存在', $this->userid);
//
//            $rs['code'] = 1;
//            $rs['msg'] = T('用户不存在');
//            return $rs;
//        }

        $rs['info'] = $info;

        return $rs;
    }

    // 增加评论
    public function addComment() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $domain = new Domain_Comment();

        $info = $domain->addComment($this->userid, $this->username, $this->topicid, $this->commentstring, $this->ishot);

//        if (empty($info)) {
//            DI()->logger->debug('注册失败', $this->mobile);
//
//            $rs['code'] = 1;
//            $rs['msg'] = T('注册失败');
//            return $rs;
//        }

        $rs['info'] = $info;

        return $rs;
    }
}